Add argument maxid to solve timeout etc

Brightcells лет %!s(int64=8): %!d(string=назад)
Родитель
Сommit
5d89870762
1 измененных файлов с 13 добавлено и 4 удалено
  1. 13 4
      main.py

+ 13 - 4
main.py

@@ -118,24 +118,32 @@ def delete_session_file(lensman, session, name):
118 118
     conn.commit()
119 119
 
120 120
 
121
-def get_new_files(lensman, session, maxt):
121
+def get_new_files(lensman, session, maxid, maxt):
122 122
     _, thumb = get_session_dir(lensman, session)
123 123
     files = glob.iglob('{}/*'.format(thumb))
124 124
     news = []
125 125
     for file_ in files:
126 126
         logit('/fetch_thumbnail', file_, key='globfile')
127 127
         if not file_.endswith('.tmp'):  # Whether 'xxx.tmp' or not
128
+            # Photo Name
128 129
             photo_name = file_.split('/')[-1]
130
+            # Photo_id
129 131
             photo_id = photo_name.split('.')[0]
132
+            # Thumb Path
130 133
             thumb_path = file_.replace('{}/'.format(ROOT_PATH), '')
134
+            # Origin Path
131 135
             origin_path = thumb_path.replace('thumbnail', 'origin')
132
-            if int(photo_id) > maxt:
133
-                insert_session_file(lensman, session, photo_id, photo_name, thumb_path, origin_path)
136
+            # Return When Photo_id Large Than Maxid
137
+            # Solve APP Doesn't Get Photo When Timeout
138
+            if int(photo_id) > maxid:
134 139
                 news.append({
135 140
                     'id': photo_id,
136 141
                     'name': photo_name,
137 142
                     'path': thumb_path,
138 143
                 })
144
+            # Insert When Photo_id Large Than Maxt
145
+            if int(photo_id) > maxt:
146
+                insert_session_file(lensman, session, photo_id, photo_name, thumb_path, origin_path)
139 147
     return news
140 148
 
141 149
 
@@ -193,9 +201,10 @@ class FetchThumbnailHandler(RequestHandler):
193 201
     def post(self):
194 202
         lensman = self.get_argument('lensman', '')
195 203
         session = self.get_argument('session', '')
204
+        maxid = int(self.get_argument('maxid', 0))
196 205
 
197 206
         maxt = get_last_timestamp(lensman, session)
198
-        files = get_new_files(lensman, session, maxt)
207
+        files = get_new_files(lensman, session, maxid, maxt)
199 208
 
200 209
         logit(self, maxt, key='maxt')
201 210
         logit(self, files, key='files')